const csv2mysqlra = require("./index");

const seqConfig = {
  dialect: "mysql",
  host: "127.0.0.1",
  port: 3306,
  database: "db",
  username: "username",
  password: "password",
};

csv2mysqlra({
  seqConfig,
  csvDirPath: "./csv",
  modelDirPath: "./model",
  batchNum: 600,
  workerNum: 6,
  logDirPath: "./log",
  // startIndex: 0,
  // endIndex: 5,
  tbNames: ["user"],
  headHandler(tbName, thRow) {
    return thRow.split(",").map((th) => th.split(".")[1]);
  },
  rowHandler(thead, tbName, row, ri) {
    const tds = row.split(",");
    return thead.reduce(
      (p, k, i) => {
        if (tds[i] !== "null") p[tf(k)] = tds[i];
        return p;
      },
      { index: ri }
    );
  },
});

function tf(str) {
  const re = /_(\w)/g;
  return str.replace(re, function ($0, $1) {
    return $1.toUpperCase();
  });
}
